package com.example.day09.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.day09.BannerBean;
import com.example.day09.Bean;
import com.example.day09.Persenter;
import com.example.day09.R;
import com.example.day09.Recy_RecyAdapter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.annotations.NonNull;


/**
 * A simple {@link Fragment} subclass.
 */
public class AFragment extends Fragment implements com.example.day09.net.View {


    private RecyclerView mRecy;
    private ArrayList<Bean.DataBean.DatasBean> beans;
    private ArrayList<BannerBean.DataBean> beaner;
    private Recy_RecyAdapter adapter;

    public AFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_a, container, false);
        Persenter persenter = new Persenter(this);
        persenter.getData();
        initView(inflate);
        return inflate;

    }

    private void initView(@NonNull final View itemView) {
        mRecy = (RecyclerView) itemView.findViewById(R.id.recy);
        mRecy.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecy.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
        beans = new ArrayList<>();
        beaner = new ArrayList<>();
        adapter = new Recy_RecyAdapter(beans, beaner, getActivity());
        mRecy.setAdapter(adapter);

    }

    @Override
        public void bean(List<Bean.DataBean.DatasBean> datasBeans) {
                beans.addAll(datasBeans);
                adapter.notifyDataSetChanged();

    }

    @Override
    public void showbanner(List<BannerBean.DataBean> bannerlist) {
            beaner.addAll(bannerlist);
            adapter.notifyDataSetChanged();
    }
}
